package com.project.class8_30.lambda;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

public class ProductTest {
    public static void main(String[] args) {
//        List<ProductBean> productList = new ArrayList<>();
//        productList.add(new ProductBean(3,"电视机",1200));
//        productList.add(new ProductBean(8,"电吹风",80));
//        productList.add(new ProductBean(2,"微波炉",600));

//        productList.sort(new Comparator<ProductBean>() {
//            @Override
//            public int compare(ProductBean o1, ProductBean o2) {
//                return o1.getId() - o2.getId();
//            }
//        });

//        productList.sort((o1,o2) -> o2.getPrice() - o1.getPrice());
//        System.out.println(productList);


        List<ProductBean> productList = new ArrayList<>();
        productList.add(new ProductBean(3,"电视机",1200));
        productList.add(new ProductBean(8,"电吹风",80));
        productList.add(new ProductBean(2,"微波炉",600));
        productList.add(new ProductBean(1,"电动机",400));
        productList.add(new ProductBean(9,"洗衣机",1500));
        productList.add(new ProductBean(5,"电磁炉",120));
        productList.add(new ProductBean(15,"笔记本电脑",4500));

//        for(ProductBean p : productList){
//            System.out.println(p);
//        }
//        productList.stream().forEach(p -> System.out.println(p));
        //得到商品名中带电的商品
//        for(ProductBean p : productList){
//            if(p.getName().indexOf("电") != -1){
//                System.out.println(p);
//            }
//        }
        productList.stream().filter(p -> p.getName().indexOf("电") != -1)
                .forEach(n -> System.out.println(n));
    }
}

